//    Copyright (C) Kherty.  All rights reserved.
using System.Diagnostics.Contracts;
using System.Reflection;
using OpenLS.Core.Notification;
using OpenLS.Core.Serialization;
using System.ComponentModel;

namespace OpenLS.Drawing
{
    public class GradientStop : ViewModelBase, IOfficeXmlSerializable
    {
        private ColorBase _color;
        private double _pos;

        public double Position
        {
            get { return _pos; }
            set { _pos = value;notifyPropertyChanged("Position"); }
        }

        public ColorBase Color
        {
            get { return _color; }
            set { _color = value; notifyPropertyChanged("Color");}
        }

        #region IOfficeXmlSerializable Members

        void IOfficeXmlSerializable.ReadXml(ReadContext context)
        {
            using (var c = context.Read("gs"))
            {
                Position = c.GetDouble("pos")/100000;
                Color = ColorBase.ReadColor(c);
            }
        }

        void IOfficeXmlSerializable.WriteXml(WriteContext context)
        {
            using (WriteContext c = context.Write("gs"))
            {
                c.SetDouble("pos", Position*100000);
                c.WriteElement(Color);
            }
        }

        #endregion

        internal System.Windows.Media.GradientStop ToGradientStop(ColorScheme colorScheme)
        {
            System.Windows.Media.GradientStop result = new System.Windows.Media.GradientStop();
            result.Offset = Position;
            result.Color = Color.ResolveColor(colorScheme);
            return result;
        }

    }
}